using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Crux.Core.EFCore.Test;
/// <summary>
/// TestModelMapping
/// </summary>
public class TestModelMapping : IEntityTypeConfiguration<TestModel>
{
    public void Configure(EntityTypeBuilder<TestModel> builder)
    {
        builder.ToTable("test_model");
        builder.HasKey(p => p.Id).HasName("id");

        var comparer = new ValueComparer<string>(
            (l, r) => string.Equals(l, r, StringComparison.OrdinalIgnoreCase),
            v => v.ToUpper().GetHashCode(),
            v => v);

        builder.Property(p => p.Name).Metadata.SetValueComparer(comparer);
        builder.Ignore(c => c.ServiceProvider);

        builder.HasQueryFilter(c => !c.Deleted);
    }
}